package com.loan.controller.sms;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.loan.common.annotation.Log;
import com.loan.common.constant.UserConstants;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.PageQuery;
import com.loan.common.core.domain.Result;
import com.loan.common.core.domain.entity.SysDept;
import com.loan.common.core.domain.entity.SysUser;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.common.enums.SmsCompanyType;
import com.loan.common.enums.SmsTemplateType;
import com.loan.system.domain.AddressEntity;
import com.loan.system.domain.ApplyEntity;
import com.loan.system.domain.SmsConfigEntity;
import com.loan.system.mapper.SmsConfigMapper;
import com.loan.system.service.SmsConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiguang on 2022/9/15 11:53
 */
@Validated
@Api(value = "短信配置", tags = {"短信配置"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/sms")
public class SmsConfigController extends BaseController {

    private final SmsConfigService smsConfigService;

    /**
     * 获取短信配置列表
     */
    @ApiOperation("获取短信配置列表")
    //@SaCheckPermissio("app:sms:list")
    @GetMapping("/page")
    public TableDataInfo<SmsConfigEntity> list(SmsConfigEntity entity, PageQuery pageQuery) {
        return smsConfigService.selectPageList(entity, pageQuery);
    }

    /**
     * 根据id查询详情
     */
    @ApiOperation("根据id查询详情")
    //@SaCheckPermissio("app:sms:query")
    @GetMapping(value = "/{id}")
    public Result<SmsConfigEntity> getInfo(@ApiParam("ID") @PathVariable Long id) {
        return Result.ok(smsConfigService.selectSmsConfigById(id));
    }

    /**
     * 新增配置
     */
    @ApiOperation("新增配置")
    //@SaCheckPermissio("app:sms:add")
    @Log(title = "新增配置", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@Validated @RequestBody SmsConfigEntity entity) {
        return toAjax(smsConfigService.insertSmsConfig(entity));
    }

    /**
     * 修改配置
     */
    @ApiOperation("修改配置")
    //@SaCheckPermissio("app:sms:update")
    @Log(title = "修改配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> update(@Validated @RequestBody SmsConfigEntity entity) {
        return toAjax(smsConfigService.updateSmsConfig(entity));
    }

    /**
     * 删除配置
     */
    @ApiOperation("删除配置")
    //@SaCheckPermissio("app:sms:remove")
    @Log(title = "删除配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result<Void> remove(@ApiParam("ID") @PathVariable("id") Long id) {
        return toAjax(smsConfigService.deleteSmsConfigById(id));
    }

    /**
     * 状态修改
     */
    @ApiOperation("状态修改")
    //@SaCheckPermissio("app:sms:edit")
    @Log(title = "状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public Result<Void> changeStatus(@RequestBody SmsConfigEntity entity) {
        return toAjax(smsConfigService.updateSmsConfigStatus(entity));
    }

    @ApiOperation("获取短信公司列表")
    //@SaCheckPermissio("app:sms:query")
    @GetMapping(value = "/getTypeList")
    public Result<List> getTypeList(){
        return Result.ok(SmsCompanyType.getList());
    }

}
